package com.imm.da.base

import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultCallback
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import com.imm.da.utils.LogHelper
import com.imm.da.utils.ToastHelper

/**
 * <p>------------------------------------------------------
 * <p> Copyright (C) 2021 zhangmz, All rights reserved.
 * <p> If there is technical discussion, you can contact zhangmz90@foxmail.com
 * <p>------------------------------------------------------
 * <p> des
 * <p>
 *
 * @author Created by Administrator
 * @date on 2021 2021/11/14 11:51
 */
abstract class BaseActivity : AppCompatActivity(), ActivityResultCallback<ActivityResult> {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
            screenHorizontal()
        }else{
            screenVertical()
        }
    }

    /**
     * 横屏切换
     */
    open fun screenHorizontal(){

    }

    /**
     * 竖屏切换
     */
    open fun screenVertical(){

    }

    /**
     * 跳转意图，同 startActivityForResult
     */
    open fun registerActivityResult(intent: Intent): ActivityResultLauncher<Intent> {
        return registerForActivityResult(ActivityResultContracts.StartActivityForResult(), this).apply {
            launch(intent)
        }
    }

    /**
     * 接收意图执行结果，同 onActivityResult
     */
    override fun onActivityResult(result: ActivityResult) {

    }

    fun toast(message : String){
        ToastHelper.toast(this, message)
    }

    fun log(message : String){
        LogHelper.v(message)
    }

}